package org.linlinjava.litemall.wx;

/**
 * 线程顺序执行
 *
 * @author zhy
 * @create 2018-11-18 12:21
 **/
public class ThreadJoin {
	public static void main(String[] args) {
		method1();
		method2();
	}

	public static void method1(){
		Thread thread1 = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("T1执行完毕");
			}
		});

		Thread thread2 = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					thread1.join();
				}catch (InterruptedException e){
					e.printStackTrace();
				}
				System.out.println("T2执行完毕");
			}
		});

		Thread thread3 = new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					thread2.join();
				}catch (InterruptedException e){
					e.printStackTrace();
				}
				System.out.println("T3执行完毕");
			}
		});
		thread3.start();
		thread2.start();
		thread1.start();
	}

	public static void method2(){
		Runnable runnable = new Runnable() {
			@Override
			public void run() {
				System.out.println(Thread.currentThread().getName()+"执行完成");
			}
		};

		Thread t1 = new Thread(runnable,"T1");
		Thread t2 = new Thread(runnable,"t2");
		Thread t3 = new Thread(runnable,"T3");
		try {
			t1.start();
			t1.join();
            t2.start();
            t2.join();
            t3.start();
            t3.join();
		}catch (InterruptedException e){
			e.printStackTrace();
		}
	}

}
